package com.master;

import static com.util.Vessel.*;

public class Gather {

    //开始登录界面
    public void Start(){
        boolean isNext = false;
        do {
            System.out.println("请输入你的选择:");
            System.out.println("1.登录  2.注册  3.退出系统");
            int choice = scanner.nextInt();
            switch(choice){
                case 1:
                    int succeed = loginSerImpl.signInService();
                    if(succeed > 0){
                        System.out.println("请选择餐桌号:");
                        int tId = scanner.nextInt();
                        home(succeed,tId);
                    }else {
                        System.out.println("账号或密码错误请重试!");
                    }
                    break;
                case 2:
                    loginSerImpl.signUpService();
                    break;
                default:
                    System.exit(0);
            }
            System.out.println("是否去登录注册界面？  1.是    2.退出");
            int next = scanner.nextInt();
            isNext = (next==1);
        }while (isNext);
    }

    //主界面
    public void home(int cId,int tId){
        boolean isFlag = true;
        do {
            System.out.println("请选择您的操作:");
            System.out.println("1.首页");
            System.out.println("2.点菜");
            System.out.println("3.购物车");
            System.out.println("4.个人中心");
            System.out.println("5.退出");
            int choice = scanner.nextInt();
            switch(choice){
                case 1:
                    System.out.println("网友评价:");
                    orderSer.orderComment();
                    home(cId,tId);
                    break;
                case 2:
                    opMenuSer.orderMeService(cId,tId);
                    break;
                case 3:
                    trolley(cId,tId);
                    break;
                case 4:
                    mind(cId,tId);
                    break;
                case 5:
                    isFlag = false;
                    break;
            }
        }while (isFlag);
    }



    //购物车
    public void trolley(int cId,int tId){
        boolean isFlag = true;
        do {
            opMenuSer.vsMealBag(cId,tId);
            System.out.println("1.管理购物车");
            System.out.println("2.继续加购");
            System.out.println("3.菜品的勾选");
            System.out.println("4.下单");
            System.out.println("5.退出");
            int choice = scanner.nextInt();
            switch(choice){
                case 1:
                    manTrolley(cId,tId);
                    break;
                case 2:
                    opMenuSer.orderMeService(cId,tId);
                    break;
                case 3:
                    sMenus(cId,tId);
                    break;
                case 4:
                    boolean isOrder = false;
                    isOrder = opMenu.isNull(cId,tId);
                    if (isOrder){
                        orderSer.OrderMenu(cId,tId);
                    }else {
                        System.out.println("购物车为空，或未勾选菜品,下单失败!");
                    }
                    break;
                case 5:
                    isFlag = false;
                    break;
            }
        }while(isFlag);

    }

    //管理购物车
    public void manTrolley(int cId,int tId){
        System.out.println("1.管理菜品数量");
        System.out.println("2.清空购物车");
        int choice = scanner.nextInt();
        switch (choice){
            case 1:
                opMenuSer.magMealBag(cId,tId);
                break;
            case 2:
                opMenu.cleanAll(cId,tId);
                break;
        }
    }

    //勾选商品
    public void sMenus(int cId,int tId){
        System.out.println("请选择您的操作:");
        System.out.println("1.全勾选");
        System.out.println("2.全取消勾选");
        System.out.println("3.更改菜品勾选状态");
        System.out.println("4.退出");
        int choice = scanner.nextInt();
        switch(choice){
            case 1:
                orderSer.selectAll(cId,tId);
                break;
            case 2:
                orderSer.cancelAll(cId,tId);
                break;
            case 3:
                boolean isNext = false;
                do {
                    opMenuSer.vsMealBag(cId,tId);
                    System.out.println("请输入您想改变选中状态的菜品编号:");
                    int inputmId = scanner.nextInt();
                    orderSer.alter(cId,inputmId,tId);
                    System.out.println("是否继续:1.继续   2.退出操作");
                    int isnext = scanner.nextInt();
                    isNext = (isnext == 1);
                }while (isNext);
                break;
            case 4:
                break;

        }
    }

    //我的
    public void mind(int cId,int tId){
        System.out.println("请选择您的操作:");
        System.out.println("1.未支付订单明细");
        System.out.println("2.已支付订单");
        System.out.println("3.开通Vip");
        System.out.println("4.Vip充值");
        System.out.println("5.评论");
        System.out.println("6.退出");
        int choice = scanner.nextInt();
        switch (choice){
            case 1:
                orderSer.unPay(cId,tId);
                break;
            case 2:
                orderSer.paid(cId);
                break;
            case 3:
                boolean vip = vipImpl.vipJudge(cId);
                if (!vip){
                    vipSer.joinVip(cId);
                }else{
                    System.out.println("您已是vip");
                    mind(cId,tId);
                }
                break;
            case 4:
                boolean vip1 = vipImpl.vipJudge(cId);
                if (vip1){
                    double balance = vipImpl.Balance(cId);
                    System.out.println("余额:" + balance);
                }else{
                    System.out.println("这是vip专属");
                    mind(cId,tId);
                }
                break;
            case 5:
                orderSer.comment(cId);
                break;
            case 6:
                break;
        }
    }

    public static void main(String[] args) {
        gather.Start();
//        gather.mind(101,1);
    }
}
